﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;
using GameEngine.View.Components;
using SilverlightClientEditor.View.Components;

namespace SilverlightShowCase.View.Components
{
    public partial class GameEditorUC :
        UserControl,
        //IGameEditorView<GamePropertiesEditorUC, LevelPropertiesEditorUC, WorldPropertiesEditorUC, MapPropertiesEditorUC, ResourcePropertiesEditorUC, ViewEditorUC, ShapePropertiesEditorUC,ThingTypePropertiesEditorUC, ThingPropertiesEditorUC, EditorGameUC, EditorLevelUC, WorldUC, MapUC, ItemUC, FrameworkElement, int>
        IMenuView<string>
    {
        //public event Action<Point> OnSizeChanged;
        //public event Action OnSaveButtonClick;
        //public event Action OnExitButtonClick;
        public const string saveButtonTag = "save";
        public const string exitButtonTag = "exit";

        public GameEditorUC()
        {
            InitializeComponent();
            //LayoutRoot.SizeChanged += MapContainer_LayoutUpdated;
            
            SaveButton.Tag = saveButtonTag;
            ExitButton.Tag = exitButtonTag;
        }

        internal void UpdateFPS(int ticks)
        {
            try
            {
                Fps.Text = ticks + " fps";
            }
            catch (Exception e)
            {
            }
        }

        ////void MapContainer_LayoutUpdated(object sender, EventArgs e)
        ////{
        ////    if (OnSizeChanged != null)
        ////        OnSizeChanged(new Point(LayoutRoot.ActualWidth, LayoutRoot.ActualHeight));
        ////}

        //#region ITileMapEditorView Members

        //public Point TileSize
        //{
        //    get;
        //    set;
        //}
        //public float MaxMapHeight
        //{
        //    get;
        //    set;
        //}
        //public float MinMapHeight
        //{
        //    get;
        //    set;
        //}
        //public float TileHeightUnit
        //{
        //    get;
        //    set;
        //}

        //public void SetMapView(WorldUC map)
        //{
        //    MapContainer.Children.Clear();
        //    MapContainer.Children.Add(map);
        //}

        //public void SetMapMenu(TerrainMenuUC menu)
        //{
        //    MapMenuContainer.Children.Clear();
        //    MapMenuContainer.Children.Add(menu);
        //}

        //public void SetWorldMenu(WorldEditorMenuUC menu)
        //{
        //    WorldMenuContainer.Children.Clear();
        //    WorldMenuContainer.Children.Add(menu);
        //}

        //public void SetItemEditorView(ItemEditorUC itemEditor)
        //{
        //    ItemEditorContainer.Children.Clear();
        //    ItemEditorContainer.Children.Add(itemEditor);
        //}

        //#endregion

        ////public void AddElement(IUIView uiElement, Point3d position, Point3d rotation)
        ////{
        ////    throw new NotImplementedException();
        ////}
        //public event OnButtonClickHandler<IGameEditorMenuViewConstants.ButtonTags> OnButtonClick;

        public void setWorldView(WorldUC view)
        {
            worldContainer.Children.Clear();
            worldContainer.Children.Add(view);
        }

        public void SetGameEditorMenu(GamePropertiesEditorUC view)
        {
            gameEditorMenuContainer.Children.Clear();
            gameEditorMenuContainer.Children.Add(view);
        }

        public void SetLevelEditorMenu(LevelPropertiesEditorUC view)
        {
            levelEditorMenuContainer.Children.Clear();
            levelEditorMenuContainer.Children.Add(view);
        }

        public void SetWorldEditorMenu(WorldPropertiesEditorUC view)
        {
            worldEditMenuContainer.Children.Clear();
            worldEditMenuContainer.Children.Add(view);
        }

        public void SetMapEditorMenu(MapPropertiesEditorUC view)
        {
            mapEditorMenuContainer.Children.Clear();
            mapEditorMenuContainer.Children.Add(view);
        }

        //public void SetViewEditorMenu(MyViewEditorMenuView view);
        //public void SetThingTypeEditorMenu(MyThingTypeEditorMenuView view);

        public void SetThingEditorMenu(ThingPropertiesEditorUC view)
        {
            thingEditorMenuContainer.Children.Clear();
            thingEditorMenuContainer.Children.Add(view);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;
            OnExternalActionButtonClick(b.Tag as string);
            //switch (b.Tag as string) { 
            //    case saveButtonTag:

            //        OnSaveButtonClick();
            //        break;
            //    case exitButtonTag:
            //        OnExitButtonClick();
            //        break;
            //}
        }

        public event OnButtonClickHandler<string> OnExternalActionButtonClick;
    }
}
